<template>
<van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="form.username"
      name="用户名"
      label="用户名"
      placeholder="请输入用户名"
      :rules="usernameRules"
    />
    <van-field
      v-model="form.password"
      type="password"
      name="密码"
      label="密码"
      placeholder="请输入密码"
      :rules="passwordRules"
      
    />
    <van-field
      v-model="form.comfirmpassword"
      type="password"
      name="确认密码"
      label="确认密码"
      placeholder="请确认密码"
      :rules="confirmpasswordRules"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      提交
    </van-button>
  </div>
</van-form>



</template>
<script setup>
import { showSuccessToast } from 'vant';
import { reactive, ref } from 'vue';
const form = reactive({
   username:'123',
   password:'123456',
   confirmpassword:'123456',
}

)
const usernameRules = ref([
    {
        required: true,
        pattern: /^\w{3,16}$/,
        message:"用户名长度为3~16个字符"
    }
])
const passwordRules = ref([
   {
    required: true,
        pattern: /^\w{6,20}$/,
        message:"密码长度为6~20个字符"

   }


])
const confirmpasswordRules = ref([
   {
    required: true,
        pattern: /^\w{6,20}$/,
        message:"密码长度为6~20个字符",
},
{
    validator: value => {
        if(value !== form.password){
            return "两次输入的密码不一致"
        }
        return true
    }
}


])
const onSubmit =function(){
    showSuccessToast("注册成功")
}

</script>
<style lang="scss" scoped>

</style>